<?php
require_once 'Datatype_file.php';

class Datatype_image extends Datatype_file
{

    private static $_mimeTypes = array
    (
        'image/png',
        'image/jpeg',
        'image/gif'
    );

    public function validate($value)
    {

       if(is_array($value))
        {
            if(isset($_FILES[$value['field']]))
            {
                $myFile = $_FILES[$value['field']];

                if($myFile['error'] == 0)
                {
                    if(in_array($myFile['type'], self::$_mimeTypes))
                        return $myFile;
                    else
                        return false;
                }
                else
                    return null;
            }
            else
                return null;

            return null;
        }


        if(is_numeric($value))
            return $value;

        if(is_null($value))
            return null;


        return false;


    }

}

